/*******************************************\
|					    |
| Header file that displays the Easy Level  |
| high scores 				    |
|					    |
| Call highscore_easy () with int score.    |
|					    |
| 					    |
\*******************************************/

FILE *fp;

/* Inserts the new highscore and prints the high score list from ./highscore_list_e.txt */
int easy_score(char name[])
{
	int x, y, i;		/* column and row */
	char buffer[20];	/* Array to read file lines into */

	clear();

	/* Prints header for high score screen. */
	mvprintw(2, (getmaxx(stdscr)/2) - 5, "HIGH SCORES");
	mvprintw(3, (getmaxx(stdscr)/2) - 5, "LEVEL: EASY");
	refresh();

	fp = fopen("highscore_list_e.txt", "a");	/* Opens highscore list to append. */

	fprintf(fp, "%s\t\t%6d", name, score);		/* Appends new name and score to file. */

	fclose(fp);
	
	system("./enter_easy.sh");		/* Runs script that organizes highscores by score. */

	x = 1;
	y = 5;

	fp = fopen("highscore_list_e.txt", "r");	/* Reopens file for reading. */

	while(fgets(buffer, 15, fp) != NULL)	/* Reads and prints the txt file line by line. */
	{
		y++;
		mvprintw(y, x, "%s", buffer);
	}	

	fclose(fp);

	mvprintw(23, 1, "Press any key to continue.");
	refresh();
	
	i = getch();

	return 0;
}

/* Allows user to enter initials for high score. */
/* Accepts every other input. Solution pending.  */
int highscore_easy()
{
	int initials = 0;
	char name[10];		/* Array to store user initials. */
	clear();
        mvprintw(4, 7, "Your score is %i", score);
        refresh();
	echo();

        while(!initials)
        {
                mvprintw(5, 7, "Please enter your initials ( xxx): ");   /* asks for user name, 3 characters long */
                refresh();
                getstr(name);               /* User enters initials */
                if(name[3] != '\0')
                {
                        mvprintw(7, 7, "Please enter 3 characters.");
                        refresh();
                }
                else
                        initials = 1;
        }

	noecho();
	
	easy_score(name);	/* Sends new name and score to update the high score list. */

	
	return 0;
}
